/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package brain.mysql;

import java.util.AbstractMap;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 *
 * @author martin
 */
public class MySqlFactory {
  public static String getNumColumn(String tableName){
    return "SELECT COUNT(SHOW COLUMNS FROM `"+tableName+"`);";
  }
  
  public static String isColumnExist(final String tableName, final String columnName){
    return "SHOW COLUMNS FROM `"+tableName+"` LIKE '"+columnName+"';";
  }

  public static String where(final Map map){
    return " WHERE " + mapToAssociation(map);
  }
  
  public static String set(final Map map){
    return " SET " + mapToAssociation(map);
  }
  
  public static String insert(){
    String tmp = new String();
    
    return tmp;
  }
  
  public static String update(){
    return new String();
  }
  
  public static String delete(){
    return new String();
  }
  
  public static String select(){
    return new String();
  }
  
  
  
  public static String mapToAssociation(final Map<CharSequence,Object> map){
    String tmp = new String();
    
    for (Map.Entry pair : map.entrySet()){
      tmp = tmp.concat(pair.getKey().toString())
               .concat("=")
               .concat(pair.getValue().toString());
    }
            
    return tmp;
  }
  
  public static Map mapThese(final Map.Entry ... these){
    Map tmp = new LinkedHashMap();
    
    for (Map.Entry pair : these){
      tmp.put(pair.getKey(), pair.getValue());
    }
    
    return tmp;
  }
  
  public static Map.Entry associate(final CharSequence key, final Object value){
    return new AbstractMap.SimpleImmutableEntry(key,value);
  }
}
